package com.woniuxy.oldobject.controller;

import com.woniuxy.oldobject.entity.ActivityRecord;
import com.woniuxy.oldobject.entity.ResponseEntity;
import com.woniuxy.oldobject.dto.SearchDto;
import com.woniuxy.oldobject.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/activity")
public class ActivityControllerr {
    @Autowired(required = false)
    ActivityService activityService;

//    获取所有的活动
    @RequestMapping("/findAll")
    public ResponseEntity findAllActivity(){
        ResponseEntity responseEntity = activityService.findAll();
        return responseEntity;
    }

//    查询活动管理表的数据 根据活动类型查询
    @RequestMapping("/activityManageByType/{activityType}")
    public ResponseEntity activityManageByType(@PathVariable String activityType){
        ResponseEntity responseEntity = activityService.activityManageByType(activityType);
        return responseEntity;
    }


    //    增加活动记录
    @RequestMapping("/addActivityRecord")
    public ResponseEntity addOneActivityRecord(@RequestBody ActivityRecord activityRecord){
        System.out.println("增加活动的参数："+activityRecord);
        ResponseEntity responseEntity = activityService.addOneActivityRecord(activityRecord);
        return responseEntity;
    }


    //    根据id删除活动记录
    @RequestMapping("/deleteOneActivityRecordById/{id}")
    public ResponseEntity deleteOneActivityRecordById(@PathVariable int id){
        ResponseEntity responseEntity = activityService.deleteOneActivityRecordById(id);
        return responseEntity;
//        return null;
    }

    //    修改一条活动记录
    @RequestMapping("/changeOneActivityRecord")
    public ResponseEntity changeOneActivityRecord(@RequestBody ActivityRecord activityRecord){
        ResponseEntity responseEntity = activityService.changeOneActivityRecord(activityRecord);
        return responseEntity;
    }


    //    按条件查询活动记录信息
    @RequestMapping("/searchActivityRecord")
    public ResponseEntity searchActivityRecord(@RequestBody SearchDto searchDto){
        ResponseEntity responseEntity = activityService.searchActivityRecord(searchDto);
        return responseEntity;
    }


    //    根据id删除活动信息
    @RequestMapping("/searchActivity")
    public ResponseEntity searchActivity(@RequestBody SearchDto searchDto){
        System.out.println("===============search===================");
        System.out.println(searchDto);
        ResponseEntity responseEntity = activityService.searchActivity(searchDto);
        System.out.println("=============结果==================");
        System.out.println(responseEntity);
        return responseEntity;
    }
}
